package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.Ill;
import com.itheima.POJO.Sport;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public interface IllMapper {
    //分页
    @Select("<script> select * from t_diseaselibrary\n" +
            "     <where>\n" +
            "        <if test=\"queryString !=null and queryString.length > 0\">\n" +
            "          code  = #{queryString} or name like nameOfDisease('%',#{queryString},'%')\n" +
            "          </if>\n" +
            "     </where></script>")
    Page<Ill> findPage(String queryString);

    //添加
    @Insert("insert into t_diseaselibrary(code,nameOfDisease,type,occupational,gender,visitingTimeLimit,visitingDepartment,warningLevel,otherName," +
            "medicalExplanation,commonCauses,advice)" +
            " values " +
            "(#{code},#{nameOfDisease},#{type},#{occupational},#{gender},#{visitingTimeLimit},#{visitingDepartment},#{warningLevel}," +
            "#{otherName},#{medicalExplanation},#{commonCauses},#{advice})")
    void add(Ill ill);


    //编辑窗口回显数据
    @Select("SELECT * FROM t_diseaselibrary WHERE id =#{id}")
    Ill findSportById(Integer id);

    //编辑
    @Update("<script>" +
            "update t_diseaselibrary\n" +
            "        <set>\n" +
            "            <if test=\"code != null\">\n" +
            "                code = #{code},\n" +
            "            </if>\n" +
            "            <if test=\"nameOfDisease != null\">\n" +
            "                nameOfDisease = #{nameOfDisease},\n" +
            "            </if>\n" +
            "            <if test=\"type != null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"occupational != null\">\n" +
            "                occupational = #{occupational},\n" +
            "            </if>\n" +
            "            <if test=\"gender != null\">\n" +
            "                gender = #{gender},\n" +
            "            </if>\n" +
            "            <if test=\"visitingTimeLimit != null\">\n" +
            "                visitingTimeLimit = #{visitingTimeLimit},\n" +
            "            </if>\n" +
            "            <if test=\"visitingDepartment != null\">\n" +
            "                visitingDepartment = #{visitingDepartment},\n" +
            "            </if>\n" +
            "            <if test=\"warningLevel != null\">\n" +
            "                warningLevel = #{warningLevel},\n" +
            "            </if>\n" +
            "            <if test=\"otherName != null\">\n" +
            "                otherName = #{otherName},\n" +
            "            </if>\n" +
            "            <if test=\"medicalExplanation != null\">\n" +
            "                medicalExplanation = #{medicalExplanation},\n" +
            "            </if>\n" +
            "            <if test=\"commonCauses != null\">\n" +
            "                commonCauses = #{commonCauses},\n" +
            "            </if>\n" +
            "            <if test=\"advice != null\">\n" +
            "                advice = #{advice},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}" +
            "</script>")
    void edit( Ill ill);

    //删除
    @Delete("DELETE  FROM t_diseaselibrary WHERE id=#{id};")
    void deleteById(Integer id);

}
